<?
    // shorthand
    class DBM extends DatabaseManager {} 
    
    // Database Manager
    class DatabaseManager {
        const DBType = "MySQL";
        private static $_dbclass;
        private static $_lastquery;
        
        static function Connect($dbhost,$user,$pass,$db) {
            require_once("dbmanagers/" . self::DBType . "DBManager.php");
            eval("self::\$_dbclass = new " . self::DBType . "DBManager('$dbhost','$user','$pass','$db');");
            if (!self::$_dbclass) {
                self::Err();
            }
        }
        static function IsConnected() {
            return (self::$_dbclass != null);
        }
        static function Query($query) {
            self::$_lastquery = $query;
            $resultset = self::$_dbclass->Query($query);
            return $resultset;
        }
        static function QueryHasRows($query) {
            return self::$_dbclass->QueryHasRows($query);
        }
        static function Execute($query) {
            self::Query($query);
        }
        static function CountRows($query) {
            return count(self::FetchAllRows($query));
        }
        static function FetchOne($query) {
            $arr = self::$_dbclass->FetchRow($query);
            if (is_array($arr)) {
                $row = array_values($arr);
                return $row[0];
            }
            else return null;
        }
        static function FetchRow($query) {
            return self::$_dbclass->FetchRow($query);
        }
        static function FetchAllRows($query) {
            return self::$_dbclass->FetchAllRows($query);
        }
        static function LastInsertID() {
            return self::$_dbclass->LastInsertID();
        }
	static function AffectedRows() {
	    return self::$_dbclass->AffectedRows();
	}
        static function Error($query,$error) {
        	if (!Conf::$PrintedHeader) Functions::PrintHeader("ERROR!!!");
        	try { throw new ComplexException($query,$error); }
        	catch(ComplexException $ce) { FatalMessage::Show($ce->Title(),$ce->Message()); }
            
        }
        
        static function Slash($str) {
            $str = addslashes($str);
            $str = preg_replace("/\\+/",'\\',$str);
            return $str;
        }
        static function Unslash($str) {
            $str = str_replace('\\','',$str);
            return $str;
        }
    }
?>
